<template>
  <div>
    <!--  表单 start https://element.eleme.cn/#/zh-CN/component/form -->
    <el-form :model="dataForm" status-icon ref="dataForm" label-width="100px" class="">
      <el-form-item label="用户名" prop="name"><el-input type="text" v-model="dataForm.name"></el-input></el-form-item>
      <el-form-item label="密码" prop="pwd"><el-input type="password" v-model="dataForm.pwd"></el-input></el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">登录</el-button>
        <el-button @click="resetForm('dataForm')">重置</el-button>
      </el-form-item>
    </el-form>
    <!--  表单 end -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataForm: {
        name: '',
        pwd: ''
      }
    };
  },
  methods: {
    submitForm() {
      var _self = this;
      _self.$ajax
        .get('http://0608.cc/login', { params: _self.dataForm })
        .then(function(response) {
          // 不管成功与失败、都弹出消息
          alert(response.data.msg);
          // 判断是否成功、成功跳转至展示页面
          if (response.data.code == 0) {
            _self.$router.push({ name: 'schoolList' });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style></style>
